Repository navigation
sync_contract_execution: re-execute contracts while syncing, or only fetch their states - #96
Merged
Merged
Conversation
…fetch their states [params] sync_contract_execution (default true, today's behaviour): contract calls are re-executed while the node reads the blockchain, and the states that end stale are fetched from the confidants once it is live. false: no re-execution while reading; every state is fetched, and syncing needs no executor. The packaged config.ini sets it explicitly. run.sh SYNC_CONTRACT_EXECUTION=0 and the scenario contracts-dice-join-nosync-exec run the network with it off. Step 4 of the contract state sync plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EnzinoBB
added a commit
that referenced
this pull request
Nov 1, 2026
…inst the chain A node that replays contract calls while syncing cannot reproduce every execution (a contract whose result depends on its own balance, for instance). Such a contract's state stays stale, the node never obtains the state the chain declares, and its later executions start from a wrong state. This change lets the node notice and repair that. - each contract's StateItem records the call and the hash of the last new_state with a state (declared_ref, declared_hash), whether or not the node obtained the state, so a node knows which contracts it holds stale (is_stale, count_stale). The declaration is serialized after the existing fields only when one is known: an item of an earlier checkpoint keeps its bytes and its hash; the quick-start validation fills it from the chain when the block is stored - once the node is live (the first live block after read ones), every stale contract is asked for from the confidants with the existing StateRequest (StateFetcher, solver/statefetcher.hpp): at most 16 a round, oldest first, each again after 50, 100, ... up to 5000 rounds - a StateReply is taken only for a contract this node asked for, and only for the declared call with the declared hash (newer, older or other states are ignored); the cache is overwritten (a re-execution may have stored a wrong state for the same call). A contract without a declaration is checked against its block as before, but no longer taken unverified when the block is not stored; a state of an unknown contract is refused - removing a block moves the declaration back to the latest successful new_state left on the chain - get_actual_state warns when a state the block declares is not available - [params] sync_contract_execution (default true, the current behaviour): false skips the re-execution of contract calls while the node reads the blockchain; every state is then fetched from the confidants once the node is live, and syncing needs no executor - unit tests in tests/csnode/smartcontracts_tests.cpp (state bookkeeping, earlier layout, the reply check) Local: the request and reply messages are the existing ones, and a node only changes what it accepts. It builds on the PR that charges emitted transactions to the latest execution (fee rule). Same change in the community fork: #95, #96 (and the warning of #83). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 4 of the contract state sync plan.
[params] sync_contract_execution, default true, which is today's behaviour and the user's choice: calls are re-executed while the node reads the blockchain, and states that end stale are fetched from the confidants once the node is live (solver: contract states fetched and verified at the head instead of re-executed #95). With false nothing is re-executed while reading, every state is fetched, and syncing does not need the executor.config.inisets it explicitly, with a comment.run.sh SYNC_CONTRACT_EXECUTION=0and the scenariocontracts-dice-join-nosync-execrun the network with the switch off. The scale runs measure both settings.Not consensus-relevant: balances do not depend on states since #94, and the states are the declared ones either way.
🤖 Generated with Claude Code